package DealCard;

import Objects.Card;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;

public class ThreadImages extends Thread {
    JLabel lbCard;
    Card c = new Card();
    int iBeginX, iBeginY;
    int iEndX, iEndY;
    double dbSpeed = 1;

    public ThreadImages(JLabel lbCard, int iBeginX, int iBeginY, int iEndX, int iEndY) {
        this.lbCard = lbCard;
        this.iBeginX = iBeginX;
        this.iBeginY = iBeginY;
        this.iEndX = iEndX;
        this.iEndY = iEndY;
    }

    @Override
    @SuppressWarnings("static-access")
    public void run() {
        double dbA = Math.atan2(iEndY - iBeginY, iEndX - iBeginX);
        double dbNextX = iBeginX;
        double dbNextY = iBeginY;
        while (true) {
            dbNextX += dbSpeed * Math.cos(dbA);
            dbNextY += dbSpeed * Math.sin(dbA);
            lbCard.setBounds((int) (dbNextX + 0.5), (int) (dbNextY + 0.5), c.getiCardWidth(), c.getiCardHeight());
            try {
                this.sleep(1);
            } catch (InterruptedException ex) {
                Logger.getLogger(ThreadImages.class.getName()).log(Level.SEVERE, null, ex);
            }
            if ((int) (dbNextX + 0.5) == iEndX && (int) (dbNextY + 0.5) == iEndY) {
                this.stop();
                break;
            }
        }
    }
}
